package lnu.project.cart;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class EnterEMAIL  extends Activity {

	Button btnSendEMAIL;
	EditText txtPhoneNo;
	EditText txtEmail;
	Activity this_activity;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.enteremail_xml);
		this_activity = this;
		btnSendEMAIL = (Button) findViewById(R.id.btnSendEMAIL);
		txtEmail = (EditText) findViewById(R.id.email);

		btnSendEMAIL.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				String Email = txtEmail.getText().toString();
				//set text message
				String message = "Shopping bag";
				if (Email.length() > 0 && message.length() > 0){
					String subject=MainActivity.BASKETNAME;
					sendEMAIL(Email,subject, message);
						finish();  
				}
				
				else
					Toast.makeText(getBaseContext(),
							"Please enter both phone number and message.",
							Toast.LENGTH_SHORT).show();
				
				
				
			}

			private void sendEMAIL(String email, String subject, String message) {
				Intent i = new Intent(Intent.ACTION_SEND);
				i.setType("text/plain");
				i.putExtra(Intent.EXTRA_EMAIL  ,email);
				i.putExtra(Intent.EXTRA_SUBJECT, subject);
				i.putExtra(Intent.EXTRA_TEXT   , message);
				try {
				    startActivity(Intent.createChooser(i, "Send mail..."));
				} catch (android.content.ActivityNotFoundException ex) {
				    Toast.makeText(EnterEMAIL.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
				}
			}
		});
	}


}